
<?php 
class XuLy_User extends database
{
	function GetNumRows()
	{
		$sql = 'select * from thanh_vien' ;
		$this->setQuery($sql);
		$tb = $this->LoadAllRow();
		$num = count($tb);
		return $num;
	}
	
	function chitiet($ma)
	{
		$this->setQuery('set names utf8');
		$this->Query();
		
		$sql = 'select* from nguoi_mua where MaSo='.$ma;	
		$this->setQuery($sql);
		$row = $this->loadOneRow();
		return $row;
	}
	
	function kiemtraacc($user, $pass)
	{
		$pass = md5($pass);
		$sql = 'select * from thanh_vien where trangthai <> 0 and tendangnhap=\''.$user.'\' and matkhau=\''.$pass.'\'';		
		$this->setQuery($sql);
		$row = $this->loadOneRow();
		return $row;
	}
	
	function KiemTraTonTaiUserName($tendangnhap)
	{
		$this->setQuery('set names utf8');
		$this->Query();
		
		$sql = 'select* from thanh_vien where trangthai <> 0 and tendangnhap=\''.$tendangnhap.'\'';	
		$this->setQuery($sql);
		$row = $this->loadOneRow();
		return $row;
	}	
	
	function KiemTraTonTaiEmail($email)
	{
		$this->setQuery('set names utf8');
		$this->Query();
		
		$sql = 'select* from thanh_vien where trangthai <> 0 and email=\''.$email.'\'';
		$this->setQuery($sql);
		$row = $this->loadOneRow();
		return $row;
	}	
	
	
	function themmoi($tendangnhap,$matkhau,$email,$hoten,$diachi,$dienthoai,$gioitinh,$ngaysinh,$hinhanh,$makichhoat)
	{
		$timezone  = 7;
		$ngaydangky = gmdate("Y/m/d H:i:s", time() + 3600*($timezone+date("I"))); 

		$this->setQuery('set names utf8');
		$this->Query();
		
		$sql = 'insert into thanh_vien(TenDangNhap, MatKhau, Email, HoTen, DiaChi, DienThoai, GioiTinh, NgaySinh, HinhAnh, NgayDangKy, TrangThai, MaKichHoat) values(\''.$tendangnhap.'\',\''.$matkhau.'\',\''.$email.'\',\''.$hoten.'\',\''.$diachi.'\','.$dienthoai.','.$gioitinh.',\''.$ngaysinh.'\',\''.$hinhanh.'\',\''.$ngaydangky.'\',0,\''.$makichhoat.'\')';
				
		$this->setQuery($sql);
		$kq = $this->Query();
		$manhomsv = mysql_insert_id();
		return $manhomsv;
	}
	
	function capnhat($mauser,$hoten,$ngaysinh,$diachi,$dienthoai,$gioitinh,$hinhanh)
	{
		$this->setQuery('set names utf8');
		$this->Query();
		
		$sql = 'update nguoi_mua set HoTen =\''.$hoten.'\','.
					'DiaChi=\''.$diachi.'\','.
					'DienThoai = '.$dienthoai.','.
					'GioiTinh = '.$gioitinh.','.
					'NgaySinh = \''.$ngaysinh.'\','.
					'HinhAnh =\''.$hinhanh.'\''.
					'where MaSo='.$mauser;
		
		$this->setQuery($sql);
		$kq = $this->Query();
		return $kq;
	}
	
	function capnhatpass($ma, $pass)
	{
		$pass = md5($pass);
		$sql = 'update thanh_vien set matkhau = \''.$pass.'\' where mauser='.$ma;		
		$this->setQuery($sql);
		$kq = $this->Query();
		return $kq;
	}
	
	function linhvucquantam()
	{
		$sql = 'select * from loai_ebook where maloai<>1 and trangthai = 1';		
		$this->setQuery($sql);
		$table = $this->LoadAllRow();

		return $table;
	}
	
	function themlinhvuc($mauser,$ID)
	{
		$this->setQuery('set names utf8');
		$this->Query();
		
		$sql = 'insert into quan_tam(MaUser, MaLoai, TrangThai) values('.$mauser.','.$ID.',1)';
				
		$this->setQuery($sql);
		$kq = $this->Query();
		
		return $kq;
	}
	
	function ktactive($mauser,$key)
	{
		$this->setQuery('set names utf8');
		$this->Query();
		
		$sql = 'select * from thanh_vien where mauser='.$mauser.' and makichhoat=\''.$key.'\'';		
		$this->setQuery($sql);
		$row = $this->loadOneRow();
		return $row;
	}
	
	function active($mauser)
	{
		$this->setQuery('set names utf8');
		$this->Query();
		
		$sql = 'update thanh_vien set trangthai=1 where mauser='.$mauser;		
		$this->setQuery($sql);
		$kq = $this->Query();
		return $kq;
	}
	
	function ktemail($email)
	{
		$sql = 'select * from thanh_vien where trangthai <> 0 and email=\''.$email.'\'';		
		$this->setQuery($sql);
		$row = $this->loadOneRow();
		return $row;
	}
	
	function resetpassUser($ma, $pass)
	{
		$pass = md5($pass);
		$sql = 'update thanh_vien set MatKhau =\''.$pass.'\' where mauser='.$ma;		
		$this->setQuery($sql);
		$kq = $this->Query();
		return $kq;
	}
}
?>